package cn.skyclass.business
{
	import cn.skyclass.beans.UserBean;
	import cn.skyclass.net.UserToken;
	
	import flash.utils.Dictionary;
	
	/**
	 * 统一管理用户的 session 数据
	 */
	public class SessionManager
	{
		public function SessionManager(singletonEnforcer:SingletonEnforcer){}
		
		private static var instance:SessionManager;				
		public static function get current():SessionManager{
			if(instance == null){				
				instance = new SessionManager(new SingletonEnforcer());
			}
			return instance;
		}


		private var wsDic:Dictionary = new Dictionary();
		
		/**
		 * 将一个键值对放入 session 中
		 * 若此键已经存在对应的数据，则直接替换之
		 */
		public function setAttribute(key:String, value:Object):void{
			this.wsDic[key] = value;
		}
		
		/**
		 * 根据键值来获取指定的属性值，若不存在，则返回 null
		 */
		public function getAttribute(key:String):Object{
			var out:Object = this.wsDic[key];
			if(out){
				return out;
			}else{
				return null;
			}
		}
		
		
		public function logout():void{
			instance = null;
		}
		
		public function clear():void{
		}
		
		/**
		 * current user's info
		 */
		public var myInfo:UserBean;		
		
		/**
		 * current user's token
		 */
		public var myToken:UserToken;
				
	}
}


// just can access this class in this file
class SingletonEnforcer {}



